package com.mytecblog.security.controller;

import com.mytecblog.article.entity.*;
import com.mytecblog.article.service.IAccountService;
import com.mytecblog.article.service.IArticleService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 用户登录控制器
 *
 * @author yg.huang
 * @version v1.0
 *          DATE  2016/10/31
 */
@Controller
public class LogonController {

    @Autowired
    private IArticleService articleService;
    @Autowired
    private IAccountService accountService;
    private Logger logger = Logger.getLogger(this.getClass());

    @RequestMapping("/logon")
    public String logon(String userName, String password) {
        Article article = new Article();
        article.setCreateTime(new Date());
        // article.setUpdateTime(new Date());
        article.setTitle("测试文章");
        article.setAuthor(1);
        article.setContent("测试文章内容测试文章内容测试文章内容测试文章内容测试文章内容");
        article.setExcerpt("摘要摘要");
        article.setCreateTime(new Date());
        article.setUpdateTime(new Date());
        articleService.save(article);
        articleService.get(article.getId());
        List<Article> articles = articleService.findAll(" id desc ");
        logger.info("数据查询完成！");
        Account account=new Account();
        account.setBalance(new BigDecimal(1));
        account.setOwner("张三");
        account.setInterestRate(new BigDecimal(10));

        accountService.save(account);

        DebitAccount debitAccount=new DebitAccount();
        debitAccount.setBalance(new BigDecimal(2));
        debitAccount.setOwner("李四");
        debitAccount.setOverdraftFee(new BigDecimal(100));
        debitAccount.setInterestRate(new BigDecimal(20));
        accountService.save(debitAccount);

        CreditAccount creditAccount=new CreditAccount();
        creditAccount.setBalance(new BigDecimal(3));
        creditAccount.setOwner("王五");
        creditAccount.setCreditLimit(new BigDecimal(10000));
        creditAccount.setInterestRate(new BigDecimal(30));
        accountService.save(creditAccount);

        VIPDebitAccount vipDebitAccount=new VIPDebitAccount();
        vipDebitAccount.setBalance(new BigDecimal(4));
        vipDebitAccount.setOwner("王六");
        vipDebitAccount.setOverdraftFee(new BigDecimal(200));
        vipDebitAccount.setInterestRate(new BigDecimal(40));
        vipDebitAccount.setVipNo("NO.100");
        accountService.save(vipDebitAccount);


        return "index";
    }

    public IArticleService getArticleService() {
        return articleService;
    }

    public void setArticleService(IArticleService articleService) {
        this.articleService = articleService;
    }

    public IAccountService getAccountService() {
        return accountService;
    }

    public void setAccountService(IAccountService accountService) {
        this.accountService = accountService;
    }
}
